package com.tang.filter;

import com.tang.utils.Base64SerializationUtils;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Tang
 * @classname GateWayTokenFilter
 * @description [  ]
 * @date 2021/5/1 15:49
 */
public class GateWayTokenFilter extends AbstractDirectTokenFilter{

    private static final String GATEWAY_TOKEN_NAME = "gateway-token";

    @Override
    protected void onUnSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response) {

    }

    @Override
    protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {

    }

    @Override
    protected Authentication getAuthentication(String token) {
        UsernamePasswordAuthenticationToken authenticationToken = Base64SerializationUtils.deserialize(
                token, UsernamePasswordAuthenticationToken.class);
        System.out.println("GateWayTokenFilter...执行");
        return authenticationToken;
    }

    @Override
    protected String getHeaderName() {
        return GATEWAY_TOKEN_NAME;
    }
}